home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / ChunkScaleView.BackModule / ChunkScaleViewPart.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  115 lines

  1. #import "ChunkScaleViewPart.h"
  2. #import <Thinker.h>
  3. #import <appkit/NXImage.h>
  4. #import <appkit/Window.h>
  5. #import <appkit/Panel.h>                // for NXRunAlertPanel()
  6. #import <dpsclient/wraps.h>
  7. #import <libc.h>
  8. #import <math.h>
  9.  
  10. @implementation ChunkScaleView                
  11.  
  12. - oneStep
  13. {
  14.   float mx, my;
  15.   float xi, yi;
  16.   
  17.   pp=p; p=n;
  18.   n=(n+1)%(NUMLINES-1);
  19.  
  20.   scale+=scale_delta;
  21.   if(scale>=1) scale=0;
  22.  
  23.   PScurrentmouse(winNum, &mx, &my);
  24.   xi=((mx-midx)/urx)*10.0;
  25.   yi=((my-midy)/ury)*10.0;
  26.  
  27.   if((count++>500) && (((mx != oldx) && (my != oldy)) || (count>30000))){
  28.     count=0;
  29.     PSsetgray(0.0);
  30.     NXRectFill(&bounds);
  31.   }
  32.   oldx=mx; oldy=my;
  33.  
  34.  
  35.   t1[n]=t1[p]+0.2*xi; if(t1[n]>(2*PI)) t1[n]-=(2*PI);
  36.   t2[n]=t2[p]+0.2*yi; if(t2[n]>(2*PI)) t2[n]-=(2*PI);
  37.   t3[n]=t3[p]+0.01;   if(t3[n]>(2*PI)) t3[n]-=(2*PI);
  38.  
  39.   x1[n]=(cos(t1[n])*s1*scale) + (cos(t2[n])*s3) + midx;
  40.   yc1[n]=(sin(t1[n])*s2*scale) + (sin(t2[n])*s4) + midy;
  41.  
  42.   PSsetrgbcolor((cos(t1[n])+1.0)/2.0,
  43.                 (cos(t2[n])+1.0)/2.0,
  44.                 (cos(t3[n])+1.0)/2.0);
  45.  
  46.   PSnewpath();
  47.   PSmoveto(x1[pp], yc1[pp]);
  48.   PSlineto(x1[p], yc1[p]);
  49.   PSlineto(x1[n], yc1[n]);
  50.   PSclosepath();
  51.   PSfill();
  52.  
  53.   return self;
  54. }
  55.  
  56. - initFrame:(NXRect *)frameRect
  57. {
  58.   [super initFrame:frameRect];
  59.   [self newSize];
  60.   winNum=[[self window] windowNum];
  61.   return self;
  62. }
  63.  
  64. - sizeTo:(NXCoord)width :(NXCoord)height
  65. {
  66.   [super sizeTo:width :height];
  67.   [self newSize];
  68.   return self;
  69. }
  70.  
  71. - newSize
  72. {
  73.   int jkl;
  74.   urx=bounds.size.width;
  75.   ury=bounds.size.height;
  76.   
  77.   midx=urx/2;
  78.   midy=ury/2;
  79.  
  80.   n = 0;
  81.   t = 0;
  82.   
  83.   // phases of the three points;
  84.   p1=0;
  85.   p2=(4*PI)/3;
  86.   p3=(2*PI)/3;
  87.   
  88.   // starting angle of each point;
  89.   t1[0]=0;
  90.   t2[0]=p2;
  91.   t3[0]=p3;
  92.  
  93.   for(jkl=0;jkl<NUMLINES;jkl++){
  94.     x1[jkl]=midx;
  95.     yc1[jkl]=midy;
  96.   }
  97.  
  98.   // s1 and s2 should define an oval that takes up middle 75% of the screen
  99.   s1 = midx*0.5; s2 = midy*0.5;
  100.   s3 = midx*0.5; s4 = midy*0.5;
  101.  
  102.   // line per is the percentage back that erase steps
  103.   lper=NUMLINES-5;
  104.  
  105.   n=lper;
  106.   p=(lper/3)*2;
  107.   pp=(lper/3);
  108.  
  109.   scale=0;
  110.   scale_delta=0.02;
  111.   return self;
  112. }
  113.  
  114. @end
  115.